package com.dao;

import java.util.List;

import com.entity.Employee;
import com.entity.Function;
import com.entity.Good;
import com.util.Page;

@SuppressWarnings("unchecked")
public class GoodsDao extends BaseDAO {

	/**
	 * 保存
	 * @param emp
	 * @return
	 */
	public boolean save(Good good){
		return this.saveObject(good);
	}
	
	/**
	 * 删除
	 * @param Good
	 * @return
	 */
	public boolean del(Good good){
		return this.deleteObject(good);
	}
	
	/**
	 * 根据ID查对象
	 * @param id
	 * @return Good
	 * @throws Exception
	 */
	public Good fundById(int id) throws Exception{
		List<Good> list = this.queryObject(Good.class,"where :id",id);
		Good Good = null;
		if(list != null && !list.isEmpty()){
			Good = list.get(0);
		}
		return Good;
	}
	
	/**
	 * 取list
	 * @return
	 */
	public List findBylist(){
		List list = null;
		try {
			list =  this.queryObject(Good.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 取分布数据
	 * @param page
	 * @return Page
	 * @throws Exception
	 */
	public Page findbyPage(Page page) throws Exception{
		return this.queryObjectForPage(Good.class, page);
	}
	
	/**
	 * 取用户角色功能列表
	 * @param roleid
	 * @return
	 */
	public List findFunctionsByRole(int roleid){
		String sql = "select distinct A.id,A.functionname,A.parentid,A.url,A.des,A.px from Good A,roles B,role_functions C where	A.id=C.functionid and B.id=C.roleid and A.id="+roleid+" or A.parentid="+roleid;
		return findObjectBySql(Good.class, sql);
	}
	
	/**
	 * 查询一级菜单
	 * @return
	 * @throws Exception
	 */
	public List findTreeTopNode() throws Exception{
		return this.queryObject(Good.class,"where ：parentid",0);
	}
	
	/**
	 * 根据ID取子菜单
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public List findTreeNodeById(int id) throws Exception{
		return this.queryObject(Good.class,"where :parentid",id);
	}
}
